<template>
  <!-- 首页分类 -->
  <!-- 如果要flex布局要加上enable-flex属性 -->
  <scroll-view scroll-y enable-flex class="home-category">
    <navigator :url="`/pages/imgCategory/index?id=${item.id}`" class="cate-item"
      v-for="item in category" :key="item.id">
      <image :src="item.cover" mode="aspectFill"></image>
      <view class="cate-name">{{item.name}}</view>
    </navigator>
  </scroll-view>
</template>

<script>
export default {
  data() {
    return {
      category: []
    }
  },
  mounted() {
    // 动态修改当前页面的标题
    uni.setNavigationBarTitle({
      title: '分类'
    })
    this.getList()
  },
  methods: {
    // 获取分类数据
    async getList() {
      const res = await this.request({
        url: 'http://157.122.54.189:9088/image/v1/vertical/category'
      })
      this.category = res.res.category
    }
  }
}
</script>

<style lang="scss" scoped>
.home-category {
  display: flex;
  flex-wrap: wrap;
  height: calc(100vh - 36px);
  padding: 6rpx 0 0 6rpx;
  .cate-item {
    position: relative;
    width: 33.33%;
    border-right: 6rpx solid #fff;
    border-bottom: 6rpx solid #fff;
    image {
      height: 240rpx;
    }

    .cate-name {
      position: absolute;
      left: 10rpx;
      bottom: 10rpx;
      width: 100%;
      height: 50rpx;
      line-height: 50rpx;
      font-size: 30rpx;
      color: #fff;
      // css3渐变
      background-image: linear-gradient(
        to right top,
        rgba(0, 0, 0, 0.2),
        rgba(0, 0, 0, 0)
      );
    }
  }
}
</style>